package my.senix.sc.controller;

import my.senix.sc.bean.Animal;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.Size;

/**
 * Created by lhs on 2018/11/17.
 */

@RestController
@Validated
public class ValidationController {


    @GetMapping("/age/{age}")
    @Valid
    public String getAge(@PathVariable(required = false) @Min(1) @Max(120) Integer age,
                         @RequestParam @Size(min = 2, max = 5) String name) {

        return age.toString();
    }


    @GetMapping("/valid/bean")
    public Animal getBean(@Validated Animal animal){

        return animal;
    }
}
